package org.csu.jpetstore.persistence;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.csu.jpetstore.domain.Order;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
public interface OrderMapper extends BaseMapper<Order> {
    @Select("SELECT * FROM orders")
    List<Order>  getOrderS();
    @Select("SELECT * FROM orders WHERE orderid = #{orderID}")
    Order getOrder(Integer ordersID);
    @Update("UPDATE orders SET isFinished=1 WHERE orderid = #{orderID}")
    void updateOrderStatusById(Integer orderID);
    @Select("SELECT * FROM orders WHERE  userid= #{userID}")
    List<Order> getOrdersByUserID(String userID);
    @Update("UPDATE orders " +
            "SET userid = #{order.userId}, " +
            "    totalprice = #{order.totalPrice}, " +
            "    cardtype = #{order.cardType}, " +
            "    creditCard = #{order.creditCard}, " +
            "    billtofirstName = #{order.billToFirstName}, " +
            "    billtolastName = #{order.billToLastName}, " +
            "    billaddr1 = #{order.billAddr1}, " +
            "    billaddr2 = #{order.billAddr2}, " +
            "    billcity = #{order.billCity}, " +
            "    billstate = #{order.billState}, " +
            "    billzip = #{order.billZip}, " +
            "    billcountry = #{order.billCountry} " +
            "WHERE orderId = #{orderID}")
    void updateOrderById(Integer orderID, Order order);
    @Insert("INSERT INTO orders (" +
            "orderid, " +
            "userid, " +
            "orderdate, " +
            "totalprice, " +
            "cardtype, " +
            "creditcard, " +
            "billtofirstname, " +
            "billtolastname, " +
            "billaddr1, " +
            "billaddr2, " +
            "billcity, " +
            "billstate, " +
            "billzip, " +
            "billcountry, " +
            "shiptofirstname, " +
            "shiptolastname, " +
            "shipaddr1, " +
            "shipaddr2, " +
            "shipcity, " +
            "shipstate, " +
            "shipzip, " +
            "shipcountry, " +
            "courier, " +
            "exprdate, " +
            "isfinished, " +
            "locale" +
            ") VALUES (" +
            "#{orderId}, " +
            "#{userId}, " +
            "#{orderDate}, " +
            "#{totalPrice}, " +
            "#{cardType}, " +
            "#{creditCard}, " +
            "#{billToFirstName}, " +
            "#{billToLastName}, " +
            "#{billAddr1}, " +
            "#{billAddr2}, " +
            "#{billCity}, " +
            "#{billState}, " +
            "#{billZip}, " +
            "#{billCountry}, " +
            "#{shipToFirstName}, " +
            "#{shipToLastName}, " +
            "#{shipAddr1}, " +
            "#{shipAddr2}, " +
            "#{shipCity}, " +
            "#{shipState}, " +
            "#{shipZip}, " +
            "#{shipCountry}, " +
            "#{courier}, " +
            "#{exprDate}, " +
            "#{isFinished}, " +
            "#{locale}" +
            ")")
    void addOrder(Order order);
}
